/*
 * CorreaFisica.cpp
 *
 *  Created on: Oct 15, 2013
 *      Author: Hernan
 */

#include "CorreaFisica.h"
#include <iostream>

using namespace std;

CorreaFisica::CorreaFisica(b2World* world, float x, float y, float ancho, float alto, string tipo):  EntidadFisica(tipo) {

	float altoCorrea = 1.0f;
	this->definicionCuerpoFisico->position.Set(x, y);
	this->cuerpoFisico = world->CreateBody(definicionCuerpoFisico);

	b2PolygonShape rectangulo;

	rectangulo.SetAsBox(altoCorrea/2, ancho);
	this->fixture = new b2FixtureDef();
	this->fixture->shape = &rectangulo;
	this->fixture->density = 2.0f;
	this->fixture->isSensor=true;

	this->cuerpoFisico->CreateFixture(this->fixture);

	this->guardarInformacionDeEntidad();
	this->alto = alto;
	this->ancho = ancho;

}

void CorreaFisica::jointear(b2World* world){

	EngranajeFisica* engranajeFisica1 = (EngranajeFisica*)this->aJointearInicial;
	EngranajeFisica* engranajeFisica2 = (EngranajeFisica*)this->aJointearFinal;

    b2Body* body1 = engranajeFisica1->obtenerCuerpo();

    b2Body* body2 = engranajeFisica2->obtenerCuerpo();

	//creo el engranaje fantasma:

    float x = body1->GetPosition().x+5;
    float y = body1->GetPosition().y+5;
    float ancho = engranajeFisica2->obtenerFixture()->shape->m_radius*2;
    cout<<"ESTO ES EL ANCHOOOOOO : "<<ancho<<endl;


	EngranajeFisica* engranajeFantasma = new EngranajeFisica(world,x,y,ancho,0, "engranaje");

    b2GearJointDef* gearJointDef1 = new b2GearJointDef();

    gearJointDef1->bodyA = body1;
    gearJointDef1->bodyB = engranajeFantasma->obtenerCuerpo();
    gearJointDef1->joint1 = engranajeFisica1->getJoint();
    gearJointDef1->joint2 = engranajeFantasma->getJoint();
    gearJointDef1->ratio = 1.0f;//engranajeFantasma->obtenerFixture()->shape->m_radius/engranajeFisica1->obtenerFixture()->shape->m_radius;
    world->CreateJoint(gearJointDef1);



    b2GearJointDef* gearJointDef2 = new b2GearJointDef();

    gearJointDef2->bodyA = engranajeFantasma->obtenerCuerpo();
    gearJointDef2->bodyB = body2;
    gearJointDef2->joint1 = engranajeFantasma->getJoint();
    gearJointDef2->joint2 = engranajeFisica2->getJoint();
    gearJointDef2->ratio = 1.0f;
    world->CreateJoint(gearJointDef2);

    cout<<"jointeo correa"<<endl;


}

void CorreaFisica::aplicarFuerzasFisicas(){
//	cout<<"VELOCIDAD ANGULAR: "<<this->aJointearInicial->obtenerVelocidadAngular()<<endl;
}

CorreaFisica::~CorreaFisica() {
	// TODO Auto-generated destructor stub
}

